package br.com.sgpv2.entity.folha;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.criteria.CriteriaBuilder.In;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import br.com.sgpv2.entity.movimentacao.Movimentacao;


@Entity
@Table(name = "fol_folha")
@SequenceGenerator(name = "sequenceFolha", sequenceName = "fol_folha_id_seq")
public class Folha implements Serializable{

	private static final long serialVersionUID = -3397843774557751574L;
	private int id;
	private Integer mes;
	private Integer ano;
	private List<Movimentacao> movimentacoes;
	private StatusFolhaEnum status;
	private boolean fechada;
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "fol_id", nullable = false)	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	@OneToMany(mappedBy = "folha", cascade = CascadeType.ALL, orphanRemoval=true)
	@LazyCollection(LazyCollectionOption.FALSE)
	public List<Movimentacao> getMovimentacoes() {
		return movimentacoes;
	}
	public void setMovimentacoes(List<Movimentacao> movimentacoes) {
		this.movimentacoes = movimentacoes;
	}
	
	@Column(name = "fol_status")
	@Enumerated(EnumType.STRING)
	public StatusFolhaEnum getStatus() {
		return status;
	}
	public void setStatus(StatusFolhaEnum status) {
		this.status = status;
	}
	
	@Column(name="fol_mes", nullable=false)
	public Integer getMes() {
		return mes;
	}
	public void setMes(Integer mes) {
		this.mes = mes;
	}
	
	@Column(name="fol_ano", nullable=false)
	public Integer getAno() {
		return ano;
	}
	public void setAno(Integer ano) {
		this.ano = ano;
	}
	
	@Transient
	public boolean getFechada() {
		boolean retorno = false;
		if(StatusFolhaEnum.FECHADA.equals(this.status)){
			retorno = true;
		}
		return retorno;
	}
	public void setFechada(boolean fechada) {
		this.fechada = fechada;
	}
}
